<template>
	<view class="container">
		<yxylInputs :inputs="inputs" @confirm="confirm"><view class="selectAddress" @tap="selectAddress">选择地址</view></yxylInputs>
	</view>
</template>

<script>
import yxylInputs from '@/components/yxyl-inputs/yxyl-inputs.vue';
export default {
	components: { yxylInputs },
	data() {
		return {
			inputs: [],
			agencyId: ''
		};
	},
	onLoad(e) {
		this.agencyId = e.agencyId;
		this.handlerInput();
		// #ifdef H5
		this.$wechat.hideMenu();
		// #endif
	},
	onShow() {
		var that = this;
		uni.$on('selectAddress', function(data) {
			that.inputs.splice(0,1,{
				title: '产品类型:',
				key: 'agencyStockType',
				type: 'radio',
				range: [{ text: '机顶盒', value: '1', checked: true }, { text: '乐活宝典', value: '2', checked: false }]
				
			})
			
			that.inputs.splice(2, 1, {
				title: '姓名',
				key: 'contact',
				placeholder: '请输入名字',
				required: true,
				type: 'text',
				errMsg: '请输入姓名',
				default: data.contact
			});
			that.inputs.splice(3, 1, {
				title: '电话号码',
				key: 'telephone',
				placeholder: '请输入电话号码',
				required: true,
				type: 'number',
				errMsg: '请输入电话号码',
				default: data.telephone
			});
			that.inputs.splice(4, 1, {
				title: '地区', keys: ['provinceId', 'cityId', 'areaId'], type: 'address', level: 3 ,
				default:[data.provinceId,data.cityId,data.areaId]
			});
			that.inputs.splice(5, 1, {
				title: '详细地址',
				key: 'address',
				placeholder: '请输入详细地址',
				required: true,
				type: 'text',
				errMsg: '请输入详细地址',
				default: data.address
			});
		});
	},
	methods: {
		confirm(e) {
			e.agencyId=this.agencyId;
			this.$http.request({
				url:'api/Agency/CreateAgencyDeliveryApplication',
				method:'PUT',
				data:e
			}).then(()=>{
				uni.showToast({
					icon:'none',
					title:'成功申请发货',
					success() {
						setTimeout(function(){
							uni.navigateBack()
						},1500)
					}
				})
			})
		},
		selectAddress() {
			uni.navigateTo({
				url: 'addressList?isSelect=true&agencyId=' + this.agencyId
			});
		},
		handlerInput()
		{
			this.inputs=[];
			this.inputs.push({
				title: '产品类型:',
				key: 'agencyStockType',
				type: 'radio',
				range: [{ text: '机顶盒', value: '1', checked: true }, { text: '乐活宝典', value: '2', checked: false }],
				default:1
			});
			this.inputs.push({ title: '数量', key: 'count', type: 'number', placeholder: '请输入数量', required: true, errMsg: '请输入数量' });
			this.inputs.push({
				title: '姓名',
				key: 'contact',
				placeholder: '请输入名字',
				required: true,
				type: 'text',
				errMsg: '请输入姓名'				
			});
			this.inputs.push({
				title: '电话号码',
				key: 'telephone',
				placeholder: '请输入电话号码',
				required: true,
				type: 'number',
				errMsg: '请输入电话号码'
			});
			this.inputs.push({ title: '地区', keys: ['provinceId', 'cityId', 'areaId'], type: 'address', level: 3 });
			this.inputs.push({
				title: '详细地址',
				key: 'address',
				placeholder: '请输入详细地址',
				required: true,
				type: 'text',
				errMsg: '请输入详细地址'
			});
			this.inputs.push({
				title: '备注',
				key: 'remark',
				placeholder: '请输入备注',		
				type: 'text',			
			})
		}
	}
};
</script>

<style lang="scss" scoped>
.selectAddress {
	background: $uni-color-main-dark;
	width: 30%;
	color: #ffffff;
	display: flex;
	justify-content: center;
	align-items: center;
	margin-top: 20rpx;
	height: 60rpx;
	border-radius: 10rpx;
}
</style>
